<?php
namespace Admin\Model;

use Think\Model;

class CustomerComplainModel extends Model{
	
	public function editCustomer( $id,$info,$state){
		$uinfo = UserModel::loadFromSession();
		$uid = $uinfo['user_id'];
		$r = array('r'=>0,'m'=>'服务器忙，请稍候再试 return','data'=>NULL);
		   $wheres = array();
		   $editres = $this->where("complain_id=".$id)->find();
		if (!$editres) {
			$r['m'] = "很抱歉，读取用户信息失败！";
			return $r;
		}
		$comreply = M('customer_complain_reply');
		$wheres['create_time'] = date('Y-m-d H:i:s');
		$wheres['content'] = $info;
		$wheres['complain_id'] = $id;
		$wheres['user_id'] = $uid;
		$wheres['last_status'] = $state;	//处理过程中添加处理状态
		$wheres['up_time'] = date('Y-m-d H:i:s');	//更新上次处理回复时间
		$cid = $comreply->add($wheres);
		if ($cid) {
			$editRtn = $comreply->where('complain_reply_id='.$cid)->find();	
			$arr = array();
			$arr['up_time'] = $editRtn['create_time'];
			// $arr['state'] = $state;
			$arr['status'] = $state;
			$map = array();
			$map['complain_id'] = array('eq',$id);
			$res = $this->where($map)->save($arr);
			if ($res) {
				$r['r'] = 1;
				$r['m'] = "用户编辑成功！";
				$r['data'] = $this->where('complain_id='.$id)->find();
				}else{
					$r['m'] = "很抱歉，用户编辑失败！";
				}
		}else{	
			$r['m'] = "很抱歉！处理不成功，请重新处理！";
		}	
		return $r;	
	}


	// public function uidback(){
	// 	$uinfo = UserModel::loadFromSession();
	// 	$uid = $uinfo['user_id'];
	// 	return $uid;		
	// }
}